package com.cmy;

import com.alibaba.fastjson.JSONObject;

import java.io.File;

/*
*JSON:类似Map集合
*{}:代表一个对象
*[]:代表数组或集合
*psvm:生成main方法
* sout:输出语句的
* alt+insert;生成代码
*alt+回车:导包快捷键
*读源码的快捷键一致
 */
public class JSONTest {
    public static void main(String[] args) {
    //实例化学生对象
        Student stu = new Student("小白",16);
        //将java对象转换为JSON字符串
        String s = JSONObject.toJSONString(stu);
        System.out.println(s);

        Student[] Students =
                new Student[]{new Student("小黑",15),
                            new Student("王五",33),
                            new Student("马六",80)};
        String s1 = JSONObject.toJSONString(Students);
        System.out.println(s1);
        Student student = JSONObject.parseObject(s, Student.class);
//        JSONObject jsonObject = JSONObject.parseObject(s1.Student.class);
//        System.out.println(student);
//        System.out.println(student.getName()+" "+student.getAge());
//        for (int i = Students.length - 1; i >= 0; i--) {
//            Student student1 = Students[i];
//
//        }
//        System.out.println(i);
        String jsonString="{\"age\":16,\"name\":\"小白\"}";
        System.out.println(jsonString);



    }


}


